<template>
  <BasicModal v-bind="$attrs" destroyOnClose title="新增详情" :width="modalWidth" :footer="null" @register="registerModal" :destroyOnClose="true">
    <Description size="middle" class="mt-4" :bordered="true" :column="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }" :data="vipRecordInfo.data" :schema="vipRecordInfoSchema" />
  </BasicModal>
</template>
<script lang="ts" setup>
import { BasicModal, useModalInner } from '@apps/antd-admin/src/components/modal';
import { reactive, ref, unref } from 'vue';
import { getBusViprecord } from '../data/viprecord.api';
import { DescItem, Description } from '@apps/antd-admin/src/components/description';
import { render } from '@apps/antd-admin/src/hooks/render/renderUtils';
import { useAppInject } from '@apps/antd-admin/src/hooks/web/use-app-inject';

const { getIsMobile } = useAppInject();
const modalWidth = ref('750px');
if (unref(getIsMobile)) {
  modalWidth.value = '80%';
}
let vipRecordInfo: Recordable = reactive({ data: {} });
const vipRecordInfoSchema: DescItem[] = [
  {
    field: 'userName',
    label: '会员姓名',
    span: 3,
  },
  {
    field: 'userPhone',
    label: '会员手机号',
    span: 3,
  },
  {
    field: 'goodsName',
    label: '卡种名称',
    span: 3,
  },
  {
    field: 'vipCardState',
    label: '会员卡状态',
    span: 3,
    render: (curVal, data) => {
      let vipCardStateArray = [
        { label: '待激活', value: 0 },
        { label: '正常', value: 1 },
        { label: '已过期', value: 2 },
        { label: '未开通', value: 3 },
        { label: '未通过', value: 4 },
        { label: '冻结', value: 5 },
        { label: '退卡中', value: 6 },
        { label: '已退卡', value: 7 },
        { label: '已转卡', value: 8 },
        { label: '已转赠', value: 9 },
        { label: '冻结（延时开通）', value: 10 },
      ];
      const vipCardState: any = vipCardStateArray.find(item => item.value == curVal);
      if (vipCardState) {
        return vipCardState.label;
      }
      return '';
    },
  },
  {
    field: 'airportName',
    label: '开卡地区',
    span: 3,
  },
  {
    field: 'employeeName',
    label: '所属销售',
    span: 3,
  },
  {
    field: 'startDate',
    label: '开卡日期',
    span: 3,
  },
  {
    field: 'isGive',
    label: '实体卡',
    span: 3,
    render: (curVal, data) => {
      const isGiveArray = [
        { label: '已给', value: 1 },
        { label: '未给', value: 2 },
      ];
      const isGive: any = isGiveArray.find(item => item.value == curVal);
      if (isGive) {
        return isGive.label;
      }
      return '';
    },
  },
  {
    field: 'isCheck',
    label: '审核状态',
    span: 3,
    render: (curVal, data) => {
      const isCheckArray = [
        { label: '审核中', value: 1 },
        { label: '区域经理通过', value: 2 },
        { label: '财务人员通过', value: 3 },
        { label: '开卡成功', value: 4 },
      ];
      const isCheck: any = isCheckArray.find(item => item.value == curVal);
      if (isCheck) {
        return isCheck.label;
      }
      return '';
    },
  },
  {
    field: 'payType',
    label: '支付类型',
    span: 3,
    render: (curVal, data) => {
      const payTypeArray = [
        { label: '迅联微信', value: 'PAY_WX' },
        { label: '易宝微信', value: 'PAY_WX_YIBAO' },
        { label: '银联微信', value: 'PAY_WX_YINLIAN' },
        { label: '农业银行微信', value: 'PAY_WX_NONGYE' },
        { label: '富友微信', value: 'PAY_WX_FUIOU' },
        { label: '富友微信小程序', value: 'PAY_WX_FUIOU_MINI' },
        { label: '交通银行微信', value: 'PAY_WX_JIAOTONG' },
        { label: '支付宝', value: 'PAY_ALI' },
        { label: '线下', value: 'PAY_UNDERLINE' },
        { label: '公司余额', value: 'PAY_COMPANY_BALANCE' },
        { label: '扫码支付', value: 'PAY_QRCODE' },
      ];
      const payType: any = payTypeArray.find(item => item.value == curVal);
      if (payType) {
        return payType.label;
      }
      return '';
    },
  },
  {
    field: 'amount',
    label: '支付金额',
    span: 3,
  },
  {
    field: 'voucherImg',
    label: '支付凭证',
    span: 3,
    render: (curVal, data) => {
      return render.renderImage({ text: curVal });
    },
  },
  {
    field: 'remark',
    label: '备注',
    span: 10,
  },
];
const isUpdate = ref(true);
const [registerModal, { setModalProps, closeModal }] = useModalInner(async data => {
  data.value = !!data?.isUpdate;
  let record = data.record;
  let queryData = await getBusViprecord({ vipRecordId: record.vipRecordId });
  vipRecordInfo.data = queryData;
});
</script>
